package com.santu.edu.supporter.biz.user.controller;


import com.santu.edu.supporter.biz.user.pojo.dto.UserDTO;
import com.santu.edu.supporter.biz.user.pojo.params.UserUpdateParam;
import com.santu.edu.supporter.biz.user.service.UserLoginService;
import com.santu.edu.supporter.biz.user.service.UserService;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * @author 12158
 */
@RestController
@Validated
@RequiredArgsConstructor
@RequestMapping("user")
public class UserController {
    private final UserService userService;

    private final UserLoginService userLoginService;

    @PostMapping("/login/by/code")
    public String loginMaByCode(@NotBlank(message = "code不能为空") String code) {
        return userLoginService.loginByCode(code);
    }

    @PostMapping("update")
    public Boolean updateUser(@RequestBody @Valid UserUpdateParam updateParam) {
        return userService.updateUser(updateParam);
    }

    @PostMapping("remove")
    public Boolean removeUser(@NotBlank(message = "userId不能为空") String userId) {
        return userService.removeUser(userId);
    }

    @GetMapping("get/user/by/userId")
    public UserDTO getUserById(@NotBlank(message = "userId不能为空") String userId) {
        return userService.getUserById(userId);
    }

}
